local extension = Package("euphonium_card", Package.CardPack)
extension.extensionName = "Euphonium"
local U = require "packages/utility/utility"

Fk:loadTranslationTable{
  ["euphonium_card"] = "京吹杀卡牌",
  ["danhuangguan"] = "单簧管",
  [":danhuangguan"] = "出牌阶段限一次，你可以调整攻击范围（1~5）。若你的攻击范围为：1，使用【杀】无次数限制；2，使用【杀】伤害+1；3，使用【杀】指定目标后令目标弃置一张牌；4，使用【杀】可额外选择一个目标；5，手牌上限+1.",
}

local danhuangguan_maxcards = fk.CreateMaxCardsSkill{
    name = "#danhuangguan_maxcards",
    correct_func = function(self, player)
      if player:hasSkill("danhuangguan") and player:getMark("@danhuangguan") == 5 then
        return 1
      end
    end
  }
local danhuangguan_attackrange = fk.CreateAttackRangeSkill{
    name = "#nzhy_shouxi_attackrange",
    fixed_func = function (self, player)
      if player:hasSkill("danhuangguan") and player:getMark("@nzhy_shouxi") ~= 0 then
        return player:getMark("@danhuangguan")
      end
    end,
  }
  local danhuangguan_targetmod = fk.CreateTargetModSkill{
    name = "#danhuangguan_targetmod",
    bypass_times = function(self, player, skill, scope)
      return player:hasSkill("danhuangguan") and player:getMark("@danhuangguan") == 1 and skill.trueName == "slash_skill" and scope == Player.HistoryPhase
    end,
  }
  local danhuangguan_trigger = fk.CreateTriggerSkill{
    name = "#danhuangguan_trigger",
    mute = true,
    events = {fk.AfterCardUseDeclared, fk.AfterCardTargetDeclared, fk.EventAcquireSkill, fk.GameStart},
    frequency = Skill.Compulsory,
    can_trigger = function(self, event, target, player, data)
      if event == fk.EventAcquireSkill then
        return data == "danhuangguan" and target == player and player.room:getTag("RoundCount")
      elseif event == fk.GameStart then
        return player:hasShownSkill("danhuangguan", true)
      end
      if player == target and player:hasSkill("danhuangguan") and data.card.trueName == "slash" then
        if event == fk.AfterCardUseDeclared then
          return player:getMark("@danhuangguan") == 2 or player:getMark("@danhuangguan") == 3
        else
          return player:getMark("@danhuangguan") == 4 and #U.getUseExtraTargets(player.room, data) > 0
        end
      end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      if event == fk.EventAcquireSkill or event == fk.GameStart then
        if table.contains(player:getAvailableEquipSlots(), Player.WeaponSlot) then
          room:abortPlayerArea(player, Player.WeaponSlot)
        end
      else
        if player:getMark("@danhuangguan") == 2 then
          data.additionalDamage = (data.additionalDamage or 0) + 1
        elseif player:getMark("@danhuangguan") == 3 then
          local room = player.room
    room:doIndicate(player.id, {data.to})
    local to = room:getPlayerById(data.to)
    room:askForDiscard(to, 1, 1, true, self.name, false)
        else if player:getMark("@danhuangguan") == 4 then
          local to = room:askForChoosePlayers(player, U.getUseExtraTargets(room, data),
          1, 1, "#danhuangguan:::")
          if #to > 0 then
            table.insert(data.tos, to)
          end
        end
        end
      end
    end,
  }
  local danhuangguan = fk.CreateActiveSkill{
    name = "danhuangguan",
    prompt = "#danhuangguan",
    frequency = Skill.Compulsory,
    card_num = 0,
    target_num = 0,
    interaction = function()
      return UI.Spin { from = 1, to = 5 }
    end,
    card_filter = Util.FalseFunc,
    can_use = function(self, player)
      return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
    end,
    on_use = function(self, room, effect)
      local player = room:getPlayerById(effect.from)
      room:setPlayerMark(player, "@danhuangguan", self.interaction.data)
    end,
  }
  danhuangguan:addRelatedSkill(danhuangguan_targetmod)
  danhuangguan:addRelatedSkill(danhuangguan_trigger)
  danhuangguan:addRelatedSkill(danhuangguan_attackrange)
  danhuangguan:addRelatedSkill(danhuangguan_maxcards)
  local danhuangguan = fk.CreateArmor{
    name = "&danhuangguan",
    suit = Card.Spade,
    number = 9,
    equip_skill = danhuangguan
  }
  --extension:addCard(danhuangguan)
  local slash = Fk:cloneCard("slash",Card.Spade, 7)
extension:addCards({
  slash:clone(Card.Spade, 8),
  slash:clone(Card.Spade, 8),
  slash:clone(Card.Spade, 9),
  slash:clone(Card.Spade, 9),
  slash:clone(Card.Spade, 10),
  slash:clone(Card.Spade, 10),

  slash:clone(Card.Club, 2),
  slash:clone(Card.Club, 3),
  slash:clone(Card.Club, 4),
  slash:clone(Card.Club, 5),
  slash:clone(Card.Club, 6),
  slash:clone(Card.Club, 7),
  slash:clone(Card.Club, 8),
  slash:clone(Card.Club, 8),
  slash:clone(Card.Club, 9),
  slash:clone(Card.Club, 9),
  slash:clone(Card.Club, 10),
  slash:clone(Card.Club, 10),
  slash:clone(Card.Club, 11),
  slash:clone(Card.Club, 11),

  slash:clone(Card.Heart, 10),
  slash:clone(Card.Heart, 10),
  slash:clone(Card.Heart, 11),

  slash:clone(Card.Diamond, 6),
  slash:clone(Card.Diamond, 7),
  slash:clone(Card.Diamond, 8),
  slash:clone(Card.Diamond, 9),
  slash:clone(Card.Diamond, 10),
  slash:clone(Card.Diamond, 13),
})

local jink = Fk:cloneCard("jink",Card.Heart, 2)
extension:addCards({
  jink,
  jink:clone(Card.Heart, 2),
  jink:clone(Card.Heart, 13),

  jink:clone(Card.Diamond, 2),
  jink:clone(Card.Diamond, 2),
  jink:clone(Card.Diamond, 3),
  jink:clone(Card.Diamond, 4),
  jink:clone(Card.Diamond, 5),
  jink:clone(Card.Diamond, 6),
  jink:clone(Card.Diamond, 7),
  jink:clone(Card.Diamond, 8),
  jink:clone(Card.Diamond, 9),
  jink:clone(Card.Diamond, 10),
  jink:clone(Card.Diamond, 11),
  jink:clone(Card.Diamond, 11),
})

local peach = Fk:cloneCard("peach",Card.Heart, 3)
extension:addCards({
  peach,
  peach:clone(Card.Heart, 4),
  peach:clone(Card.Heart, 6),
  peach:clone(Card.Heart, 7),
  peach:clone(Card.Heart, 8),
  peach:clone(Card.Heart, 9),
  peach:clone(Card.Heart, 12),
  peach:clone(Card.Heart, 12),
})

local dismantlement = Fk:cloneCard("dismantlement",Card.Spade,3)

extension:addCards({
  dismantlement,
  dismantlement:clone(Card.Spade, 4),
  dismantlement:clone(Card.Spade, 12),

  dismantlement:clone(Card.Club, 3),
  dismantlement:clone(Card.Club, 4),

  dismantlement:clone(Card.Heart, 12),
})

local snatch = Fk:cloneCard("snatch",Card.Spade,3)

extension:addCards({
  snatch,
  snatch:clone(Card.Spade, 4),
  snatch:clone(Card.Spade, 11),

  snatch:clone(Card.Diamond, 3),
  snatch:clone(Card.Diamond, 4),
})

local duel = Fk:cloneCard("duel",Card.Spade,1)

extension:addCards({
  duel,

  duel:clone(Card.Club, 1),

  duel:clone(Card.Diamond, 1),
})

local collateral = Fk:cloneCard("collateral",Card.Club,13)

extension:addCards({
  collateral,
  collateral:clone(Card.Club, 13),
})

local exNihilo =  Fk:cloneCard("ex_nihilo",Card.Heart,7)

extension:addCards({
  exNihilo,
  exNihilo:clone(Card.Heart, 8),
  exNihilo:clone(Card.Heart, 9),
  exNihilo:clone(Card.Heart, 11),
})

local nullification = Fk:cloneCard("nullification",Card.Spade,11)

extension:addCards({
  nullification,

  nullification:clone(Card.Club, 12),
  nullification:clone(Card.Club, 13),

  nullification:clone(Card.Diamond, 12),
})

local savageAssault = Fk:cloneCard("savage_assault",Card.Spade,7)

extension:addCards({
  savageAssault,
  savageAssault:clone(Card.Spade, 13),
  savageAssault:clone(Card.Club, 7),
})

local archeryAttack = Fk:cloneCard("archery_attack",Card.Heart,1)

extension:addCards({
  archeryAttack,
})

local godSalvation = Fk:cloneCard("god_salvation",Card.Heart,1)

extension:addCards({
  godSalvation,
})

local amazingGrace = Fk:cloneCard("amazing_grace",Card.Heart,3)

extension:addCards({
  amazingGrace,
  amazingGrace:clone(Card.Heart, 4),
})

local lightning = Fk:cloneCard("lightning",Card.Spade,1)

extension:addCards({
  lightning,
  lightning:clone(Card.Heart, 12),
})

local indulgence =  Fk:cloneCard( "indulgence",Card.Spade,6)

extension:addCards({
  indulgence,
  indulgence:clone(Card.Club, 6),
  indulgence:clone(Card.Heart, 6),
})

local crossbow = Fk:cloneCard(  "crossbow",Card.Club,1)

extension:addCards({
  crossbow,
  crossbow:clone(Card.Diamond, 1),
})

local qingGang = Fk:cloneCard(  "qinggang_sword",Card.Spade,6)
extension:addCards({
  qingGang,
})

local iceSword =  Fk:cloneCard(  "ice_sword",Card.Spade,2)

extension:addCards({
  iceSword,
})

local doubleSwords = Fk:cloneCard(  "double_swords",Card.Spade,2)

extension:addCards({
  doubleSwords,
})


extension:addCards({
  Fk:cloneCard(  "blade",Card.Spade,5)
})


extension:addCards({
  Fk:cloneCard(  "spear",Card.Spade,12)
})


extension:addCards({
  Fk:cloneCard(  "axe",Card.Diamond,5)
})


extension:addCards({
  Fk:cloneCard(  "halberd",Card.Diamond,12)
})



extension:addCards({
  Fk:cloneCard(  "kylin_bow",Card.Heart,5)
})

local eightDiagram = Fk:cloneCard(  "eight_diagram",Card.Spade,2)

extension:addCards({
  eightDiagram,
  eightDiagram:clone(Card.Club, 2),
})



extension:addCards({
  Fk:cloneCard(  "nioh_shield",Card.Club,2)
})


extension:addCards({
  Fk:cloneCard(  "dilu",Card.Club,5)
})

extension:addCards({
  Fk:cloneCard(  "jueying",Card.Spade,5)
})


extension:addCards({
  Fk:cloneCard(  "zhuahuangfeidian",Card.Heart,13)
})


extension:addCards({
  Fk:cloneCard(  "chitu",Card.Heart,5)
})

extension:addCards({
  Fk:cloneCard(  "dayuan",Card.Spade,13)
})

extension:addCards({
  Fk:cloneCard(  "zixing",Card.Diamond,13)
})

local thunderSlash = Fk:cloneCard("thunder__slash")

extension:addCards{
  thunderSlash:clone(Card.Club, 5),
  thunderSlash:clone(Card.Club, 6),
  thunderSlash:clone(Card.Club, 7),
  thunderSlash:clone(Card.Club, 8),
  thunderSlash:clone(Card.Spade, 4),
  thunderSlash:clone(Card.Spade, 5),
  thunderSlash:clone(Card.Spade, 6),
  thunderSlash:clone(Card.Spade, 7),
  thunderSlash:clone(Card.Spade, 8),
}

local fireSlash = Fk:cloneCard("fire__slash")

extension:addCards{
  fireSlash:clone(Card.Heart, 4),
  fireSlash:clone(Card.Heart, 7),
  fireSlash:clone(Card.Heart, 10),
  fireSlash:clone(Card.Diamond, 4),
  fireSlash:clone(Card.Diamond, 5),
}

local analeptic = Fk:cloneCard("analeptic",Card.Spade,3)
extension:addCards({
  analeptic,
  analeptic:clone(Card.Spade, 9),
  analeptic:clone(Card.Club, 3),
  analeptic:clone(Card.Club, 9),
  analeptic:clone(Card.Diamond, 9),
})

local ironChain = Fk:cloneCard("iron_chain")
extension:addCards{
  ironChain:clone(Card.Spade, 11),
  ironChain:clone(Card.Spade, 12),
  ironChain:clone(Card.Club, 10),
  ironChain:clone(Card.Club, 11),
  ironChain:clone(Card.Club, 12),
  ironChain:clone(Card.Club, 13),
}

local fireAttack = Fk:cloneCard("fire_attack")
extension:addCards{
  fireAttack:clone(Card.Heart, 2),
  fireAttack:clone(Card.Heart, 3),
  fireAttack:clone(Card.Diamond, 12),
}

local supplyShortage = Fk:cloneCard("supply_shortage")
extension:addCards{
  supplyShortage:clone(Card.Spade, 10),
  supplyShortage:clone(Card.Club, 4),
}

local gudingBlade = Fk:cloneCard('guding_blade',Card.Spade,1)

extension:addCard(gudingBlade)

local fan = Fk:cloneCard("fan",Card.Diamond,1)

extension:addCard(fan)

local vine = Fk:cloneCard("vine")
extension:addCards{
  vine:clone(Card.Spade, 2),
  vine:clone(Card.Club, 2),
}

local silverLion = Fk:cloneCard("silver_lion",Card.Club,1)
extension:addCard(silverLion)

local huaLiu = Fk:cloneCard("hualiu",Card.Diamond,13)

extension:addCards({
  huaLiu,
})

extension:addCards{
  Fk:cloneCard("jink", Card.Heart, 8),
  Fk:cloneCard("jink", Card.Heart, 9),
  Fk:cloneCard("jink", Card.Heart, 11),
  Fk:cloneCard("jink", Card.Heart, 12),
  Fk:cloneCard("jink", Card.Diamond, 6),
  Fk:cloneCard("jink", Card.Diamond, 7),
  Fk:cloneCard("jink", Card.Diamond, 8),
  Fk:cloneCard("jink", Card.Diamond, 10),
  Fk:cloneCard("jink", Card.Diamond, 11),

  Fk:cloneCard("peach", Card.Heart, 5),
  Fk:cloneCard("peach", Card.Heart, 6),
  Fk:cloneCard("peach", Card.Diamond, 2),
  Fk:cloneCard("peach", Card.Diamond, 3),

  Fk:cloneCard("nullification", Card.Heart, 1),
  Fk:cloneCard("nullification", Card.Heart, 13),
  Fk:cloneCard("nullification", Card.Spade, 13),
}
  return extension